import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
//import 'element-ui/lib/theme-default/index.css'
import 'element-ui/lib/theme-chalk/index.css'
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'

import routes from './routes'
import 'font-awesome/css/font-awesome.min.css'
import axios from 'axios'
import global from './common/js/global.js'
import Bus from './util/bus'
import './util/directives'
import VueResource from 'vue-resource'
import {get, post} from './util/axios'

/*
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
*/

Vue.use(ElementUI);
Vue.use(VueRouter);
Vue.use(Vuex);
Vue.use(VueResource);

Vue.prototype.$axios = {
    get,
    post,
};//定义axios标签
Vue.prototype.$Bus = Bus;
Vue.prototype.$serverUrl ="http://192.168.1.5:9000/dbfg/";
//NProgress.configure({ showSpinner: false });

// Vue.prototype.$global = global;

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
      //必须先登陆时执行
      // next({ path: '/login' })
      next()
  } else {
    next()
  }
});

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  global,
  //components: { App }
  render: h => h(App)
}).$mount('#app');

